{% extends 'teacher/base.html' %}
{% load staticfiles %}
{% block content %}

        <!-- Page Heading -->
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">
                    Overview
                    <small>Teacher's Course Overview Page</small>
                </h1>
                <ol class="breadcrumb">
                    <li>
                        <i class="fa fa-suitcase"></i>  <a href="/teaching">Teaching</a>
                    </li>
                    <li>
                        <i class="fa fa-compass"></i> {{ course.title }}
                    </li>
                    <li class="active">
                        <i class="fa fa-sitemap"></i> Overview
                    </li>
                </ol>

            </div>
        </div>
        <!-- /.row -->

        {% if review == None %}

        <!-- Submit course for Review -->
        <div class="jumbotron">
            <h1>Course Registration</h1>
                <p>To have your course available on AcademicsToday, you must first submit your course for review. We will look over it and either accept it or provide feedback on how to improve the course before release.</p>
                <p>Please not illegal stuff will be outrightly rejected.</p>
                <p><a onclick="ajax_submit_course();"
                           id="submit_course_btn"
                         name="submit_course_btn"
                        class="btn btn-primary btn-lg"
                         role="button">Submit for Review »</a>
            </p>
        </div>
        <!-- /.row -->

        <!-- Registrar Status Information -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><i class="fa fa-bar-chart-o fa-university"></i> Registrar Status Information</h3>
                    </div>
                    <div class="panel-body">
                        <h2>Course Requirements</h2>
                        <p>These requirements must be met to be considered acceptable course by the registrar</p>
                        <div class="table-responsive">
                            <table class="table table-bordered table-hover table-striped">
                                <thead>
                                    <tr>
                                        <th>Requirement</th>
                                        <th>Minimum Needs</th>
                                        <th>Meets Requirement</th>
                                    </tr>
                                </thead>
                                <tbody>
                                <!-- HAS AT LEAST A SINGLE ANNOUNCEMENT -->
                                {% if announcements.count >= 1 %}
                                    <tr class="success">
                                        <td>Announcements</td>
                                        <td>1 Announcement</td>
                                        <td>Yes</td>
                                    </tr>
                                {% else %}
                                    <tr class="danger">
                                        <td>Announcements</td>
                                        <td>1 Announcement</td>
                                        <td>No</td>
                                    </tr>
                                {% endif %}

                                <!-- HAS AT LEAST A SYLLABUS PDF UPLOADED -->
                                {% if syllabus == None %}
                                    <tr class="danger">
                                        <td>Syllabus</td>
                                        <td>1 PDF Document</td>
                                        <td>No</td>
                                    </tr>
                                {% else %}
                                    <tr class="success">
                                        <td>Syllabus</td>
                                        <td>1 PDF Document</td>
                                        <td>Yes</td>
                                </tr>
                                {% endif %}

                                <!-- HAS AT LEAST A POLICY PDF UPLOADED -->
                                {% if policy == None %}
                                    <tr class="danger">
                                        <td>Grades and Policy</td>
                                        <td>1 PDF Document</td>
                                        <td>No</td>
                                    </tr>
                                {% else %}
                                    <tr class="success">
                                        <td>Grades and Policy</td>
                                        <td>1 PDF Document</td>
                                        <td>Yes</td>
                                    </tr>
                                {% endif %}

                                <!-- HAS AT LEAST 2 COURSE LECTURES -->
                                {% if lectures.count >= 2 %}
                                    <tr class="success">
                                        <td>Lectures Count</td>
                                        <td>2 Lectures</td>
                                        <td>Yes</td>
                                    </tr>
                                {% else %}
                                    <tr class="danger">
                                        <td>Lectures Count</td>
                                        <td>2 Lectures</td>
                                        <td>No</td>
                                    </tr>
                                {% endif %}

                                <!-- HAS AT LEAST ONE ASSIGNMENT -->
                                {% if assignments.count >= 1 %}
                                    <tr class="success">
                                        <td>Assignments Count</td>
                                        <td>1 Assignment</td>
                                        <td>Yes</td>
                                    </tr>
                                {% else %}
                                    <tr class="danger">
                                        <td>Assignments Count</td>
                                        <td>1 Assignment</td>
                                        <td>No</td>
                                    </tr>
                                {% endif %}

                                <!-- HAS AT LEAST ONE QUIZ -->
                                {% if quizzes.count >= 1 %}
                                    <tr class="success">
                                        <td>Quizzes Count</td>
                                        <td>1 Quiz</td>
                                        <td>Yes</td>
                                    </tr>
                                {% else %}
                                    <tr class="danger">
                                        <td>Quizzes Count</td>
                                        <td>1 Quiz</td>
                                        <td>No</td>
                                    </tr>
                                {% endif %}

                                <!-- HAS AT LEAST 1 EXAM -->
                                {% if exams.count >= 1 %}
                                    <tr class="success">
                                        <td>Exams Count</td>
                                        <td>1 Exam</td>
                                        <td>Yes</td>
                                    </tr>
                                {% else %}
                                    <tr class="danger">
                                        <td>Exams Count</td>
                                        <td>1 Exam</td>
                                        <td>No</td>
                                    </tr>
                                {% endif %}
                                
                                <!-- HAS FINAL EXAM -->
                                {% if has_final_exam == True %}
                                <tr class="success">
                                    <td>Has a Final Exam</td>
                                    <td>A exam has Is Final set to True</td>
                                    <td>Yes</td>
                                </tr>
                                {% else %}
                                <tr class="danger">
                                    <td>Has a Final Exam</td>
                                    <td>1 Final Exam</td>
                                    <td>Yes</td>
                                </tr>
                                {% endif %}
                                
                                <!-- MARK WORTH ADDS TO 100% -->
                                {% if total_final_mark_worth == 100 %}
                                <tr class="success">
                                    <td>Total Final Mark Worth</td>
                                    <td>100%</td>
                                    <td>Yes</td>
                                </tr>
                                {% else %}
                                <tr class="danger">
                                    <td>Total Final Mark Worth</td>
                                    <td>100%</td>
                                    <td>No, calculated: {{ total_final_mark_worth }}%</td>
                                </tr>
                                {% endif %}
                                </tbody>
                            </table>
                        </div>
                        
                    </div>
                </div>
            </div>
        </div>
        <!-- /.row -->
        
        {% else %}
        
        <!-- Congradulations -->
        <div class="jumbotron">
            <h1>Course Registrated!</h1>
            <p>Course is now available for students to enroll in an participate.</p>
            </p>
        </div>
        <!-- /.row -->

        <!-- Row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <h2>Review Status</h2>
                        <p>These requirements must be met to be considered acceptable course by the registrar</p>
                        <div class="table-responsive">
                            <table class="table table-bordered table-hover table-striped">
                                <thead>
                                    <tr>
                                        <th>Submission Date</th>
                                        <th>Status</th>
                                        <th>Message</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>{{ review.submission_date }}</td>
                                        <td>
                                            {% if review.status == COURSE_SUBMITTED_FOR_REVIEW_STATUS %}
                                            Waiting for Review
                                            {% elif review.status == COURSE_IN_REVIEW_STATUS %}
                                            In Review
                                            {% elif review.status == COURSE_REJECTED_STATUS %}
                                            Rejected
                                            {% elif review.status == COURSE_AVAILABLE_STATUS %}
                                            Accepted
                                            {% elif review.status == COURSE_AVAILABLE_STATUS %}
                                            Unavailable
                                            {% else %}
                                            Unknown State
                                            {% endif %}
                                        </td>
                                        <td>{{ review.from_reviewer }}</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div><!-- /.panel-body -->
                </div>
            </div>
        </div>
        <!-- /.row -->
        
        {% endif %}

<!-- Modal -->
<div id="ajax_syllabus_modal"
   name="ajax_syllabus_modal"></div>
<!-- end modal -->

<script>
    function ajax_submit_course()
    {
        $('#submit_course_btn').prop("disabled", true);
        $.ajax( 'submit_course_for_review', {
               data: {
                    'csrfmiddlewaretoken': '{{ csrf_token }}',
               },
               type: 'post',
               success: function(result) {
                    // success code execution here
                    if (result.status == 'success')
                    {
                        refresh_page();
                    }
                    else
                    {
                        var message = "Cannot submit for review. Reason: ";
                        message += result.message;
                        alert(message);
                    }
               },
               error: function(xhr,status,error) {
                    // error code here
               },
               complete: function(xhr,status) {
                    // completion code here
                    $('#submit_course_btn').prop("disabled", false);
               }
        });
    }

    /**
     *  Function makes the current tab refresh the page.
     */
    function refresh_page()
    {
        window.location = '{{ tab }}';
    }
    </script>


{% endblock content %}
